<script>
	import {
		CreateIM
	} from "@/commons/util.des.js";
	export default {
		globalData: {
			// 原始会话列表
			sessions: [],
			code: '',
			set: 1,
			// 会话列表
			huihua: [],
			//  首页邀请进厅
			yqjtnei: {


			},
			// 开关
			yqjt: false,

		},

		onLoad(e) {
			console.log(e, '渠道')


		},

		onLaunch(e) {

			console.log(e, '渠道')
			var _this = this





			if (e.path == 'pages/index/index') {
				if (e.query.name) {
					uni.login({
						provider: "weixin",
						success: (loginRes) => {
							console.log(loginRes.code, 'codecodecodecodecodecodecodecode');
							_this.code = loginRes.code;

							_this.jihuo(e.query.name, loginRes.code)
						},
						fail: () => {
							uni.showToast({
								title: "获取 code 失败",
								icon: "none",
							});
						},
					});

					console.log('渠道id缓存', 1)
					uni.setStorage({
						key: 'qudao',
						data: e.query.name,
						success: function() {
							console.log('success');
						}
					});

				} else {
					console.log('渠道id缓存', 2)
					uni.setStorage({
						key: 'qudao',
						data: 'xcx_wx_lika',
						success: function() {
							console.log('success');
						}
					});

				}

			} else {

				console.log('渠道id缓存', 3)
				uni.setStorage({
					key: 'qudao',
					data: 'xcx_wx_lika',
					success: function() {
						console.log('success');
					}
				});

			}







			var _this = this

			setTimeout(function() {
				_this.jlim()

			}, 1000);



		},

		mounted() {




			// 获取设备信息
			var that = this;
			uni.getSystemInfo({
				success: function(res) {
					uni.setStorage({
						key: 'getSystemInfo',
						data: res,
						success: function() {
							console.log('success');
						}
					});



				}
			})






		},


		methods: {




			jihuo(e, i) {

				var _this = this
				var deviceId = uni.getStorageSync("getSystemInfo").deviceId


				// return
				// http://123.57.42.55:20100/api/newApi/wechat/activateWechatUser


				var data = {
					url: "/web/v2/api/newApi/wechat/activateWechatUser",
					methods: "post",
					data: {
						code: _this.code,
						oaid: uni.getStorageSync("getSystemInfo").deviceId,
						channelId: e,

					},
				};


				 


				this.$http(data).then((res) => {

					console.log(res, "激活")
					if (res.data.code == 21000) {

					}
				});
			},





















			// 建立im

			jlim() {

				var res = uni.getStorageSync("userInfo")

				if (res != "") {

					CreateIM(res.userId, res.imPwd, 0)

				}


			}


		}


	}
</script>
<style lang="scss">
	/*每个页面公共css */
	scroll-view ::-webkit-scrollbar {

		display: none !important;

		width: 0 !important;

		height: 0 !important;

		-webkit-appearance: none;

		background: transparent;

	}

	* {
		margin: 0;
		padding: 0;
	}

	li {
		list-style-type: none;
	}

	html,
	body {
		font-family: SourceHanSansCN-Medium;
	}

	page {
		width: 100%;
		height: 100%;
		background: #FFFFFF;
	}

	uni-toast {
		z-index: 999999;
	}

	uni-modal {
		z-index: 999999;
	}
</style>
